package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heima.article.service.AIChatService;
import com.heima.article.service.ApArticleService;
import com.heima.article.service.ArticleClassifyService;
import com.heima.article.service.ArticleContentService;
import com.heima.model.article.dtos.ChatRecordDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ArticleContent;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName ArticleClassifyServiceImpl
 * @Description TODO
 * @Author Neo
 * @Date 2024/3/7 22:10
 * @Version 1.0
 */
@Component
public class ArticleClassifyServiceImpl implements ArticleClassifyService {

    @Autowired
    private ApArticleService apArticleService;

    @Autowired
    private AIChatService aiChatService;
    @Autowired
    private ArticleContentService articleContentService;


    @Override
    public String classifyArticle(String id, String content) {
        if(StringUtils.isNotBlank(id)){
            ApArticle article = apArticleService.getById(id);
            if (null!=article){
                ResponseResult<String> res = aiChatService.chat2("请分析一下内容：" + article + "将此内容分类给最合适的标签，标签如下：算法\n" +
                        "语法\n" +
                        "操作系统\n" +
                        "Java\n" +
                        "Python\n" +
                        "人工智能\n" +
                        "数据库\n" +
                        "前端\n" +
                        "硬件开发，你只需回答标签名称，不需要做其他解释，如果没有符合的，就回答“其它”。");
                return res.getData();
            }
        }else if(StringUtils.isNotBlank(content)){
            ResponseResult<String> res = aiChatService.chat2("请分析一下内容：" + content + "将此内容分类给最合适的标签，标签如下：算法\n" +
                    "语法\n" +
                    "操作系统\n" +
                    "Java\n" +
                    "Python\n" +
                    "人工智能\n" +
                    "数据库\n" +
                    "前端\n" +
                    "硬件开发，你只需回答标签名称，不需要做其他解释，如果没有符合的，就回答“其它”。");
            return res.getData();
        }
        return null;
    }

    @Override
    public String simplifyArticle(String id, String content) {
        if(StringUtils.isNotBlank(id)){
            QueryWrapper<ArticleContent> articleContentQueryWrapper = new QueryWrapper<>();
            articleContentQueryWrapper.eq("article_id",id);
            ArticleContent one = articleContentService.getOne(articleContentQueryWrapper);
            if (null!=one){
                ResponseResult<String> res = aiChatService.chat2("请精简提炼一下内容：" + one.getContent());
                return res.getData();
            }
        }else if(StringUtils.isNotBlank(content)){
            ResponseResult<String> res = aiChatService.chat2("请精简提炼一下内容：" + content);
            return res.getData();
        }
        return null;
    }

    @Override
    public ResponseResult chatRecord(ChatRecordDto dto) {
        if(StringUtils.isBlank(dto.getContent())||StringUtils.isBlank(dto.getUserId())){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }

        return null;
    }
}
